package com.algorithm.round;

/**
 * 银行家舍入法
 *
 * @author zhaoyiwu
 * @create 2017-09-29 15:30
 **/
public class BankerRounding {


    public static void main(String[] args) {

        //testRound();
        //testCeil();
        testFloor();
    }

    //Math.round() 数字加0.5，向下取值
    public static void testRound(){
        System.out.println("2.5四舍五入round: "+Math.round(2.5));
        System.out.println("3.5四舍五入round: "+Math.round(3.5));
        System.out.println("2.5000001四舍五入round: "+Math.round(2.5000001));
        System.out.println("12.5四舍五入round: "+Math.round(12.5));
        System.out.println("-12.5四舍五入round: "+Math.round(-12.5));
    }

    //Math.ceil() 向上取值
    public static void testCeil(){
        System.out.println("2.5四舍五入ceil: "+Math.ceil(2.5));
        System.out.println("3.5四舍五入ceil: "+Math.ceil(3.5));
        System.out.println("2.5000001四舍五入ceil: "+Math.ceil(2.5000001));
        System.out.println("12.5四舍五入ceil: "+Math.ceil(12.5));
        System.out.println("-12.5四舍五入ceil: "+Math.ceil(-12.5));
    }

    //Math.floor() 向下取值
    public static void testFloor(){
        System.out.println("2.5四舍五入floor: "+Math.floor(2.5));
        System.out.println("3.5四舍五入floor: "+Math.floor(3.5));
        System.out.println("2.5000001四舍五入floor: "+Math.floor(2.5000001));
        System.out.println("12.5四舍五入floor: "+Math.floor(12.5));
        System.out.println("-12.5四舍五入floor: "+Math.floor(-12.5));
    }



}
